package com.cyys.modules.system.controller;

import com.cyys.common.ql.AR;
import com.cyys.modules.core.controller.BaseAction;
import com.cyys.modules.core.sysParam.SystemConfigureUtil;
import com.cyys.modules.core.sysParam.SystemConstants;
import com.cyys.modules.system.service.user.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sys/main")
public class ManageMainAction extends BaseAction {
	
	@Resource
	private UserService userService;

	@GetMapping("/index")
	public String main()  {
		return "module/main";
	}
	
	@GetMapping("/console")
	public String console(Model model)  {
		if(getUser().getType().equals("1")) {
			return "module/console";
		} else if(getUser().getType().equals("3")){
			return "module/console-sub";
		}
		return "module/console";
	}
	
	@GetMapping("/editPwd/input")
	public String editPwdInput(String userId, Model model)  {
		model.addAttribute("pwdStrength", SystemConfigureUtil.get(SystemConstants.PWD_STRENGTH));
		return "module/edit-pwd";
	}

	@ResponseBody
	@PostMapping("/editPwd/save")
	public AR editPwd(String oldPassword, String password)  {
		String userId = getUser().getId();
		return userService.editPwd(userId, oldPassword, password);
	}
	
}
